#
require 'rubygems'
require 'gratr/import'
require 'gratr/dot'
require 'rgl/dot'

class DataSet
  
  def initialize
    @vertice_map = {}
    @data = []
  end
  
  #
  ## return Array of Arrays of numbers
  def get_data_from(fname)
    return @data unless @data.empty?
    
    file = File.open fname
    file.each_line do |line| 
      @data << line.split.collect do |el|
        el.to_i
      end
    end
    
    return @data
  end # - get_data_from(fname)
  
  #
  ## returns hash of the vertices data read from file
  def to_hash
    raise "No data fed, use call *get_data_from(fname)* before." if @data.empty?
    
    @data.each do |vertice|
      @vertice_map[vertice.shift] = vertice
    end
    
    @vertice_map
  end # - to_hash
  
  #
  ## returns gratr Graph object
  def to_graph
    graph = UndirectedGraph[]
    
    to_hash.each do |v, connections|
      connections.each do |con|
        graph << v
        graph << con
      end
    end
    
    graph
  end
  
end # - DataSet

#
class Pq_03_Solver
  def self.am
    g = UndirectedGraph[1,2, 2,3, 1,3]
    g.write_to_graphic_file('jpg') 
    puts "here"
  end
  
  def self.solve
    data_set = DataSet.new
    data_set.get_data_from 'trunk/pq-s/pq-03/kargerAdj.txt'
    vertices = data_set.to_hash
  end
end

#puts Pq_03_Solver.am